package com.jchy.renderit.test;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;

public class FrameExample2 extends JFrame {
	
  static final long serialVersionUID = 999;
	
  private JButton myButton;
  private Color color;
  private Container container;

  public FrameExample2() {
    super("Testing a Frame with a single button");

    container = getContentPane();

    myButton = new JButton("Color");   // Create a button with name color
    myButton.setToolTipText("Button changes the background color");
 //   myButton.setBackground(Color.cyan);
    myButton.addActionListener(
      new ActionListener()  {
        public void actionPerformed(ActionEvent e)
        {
          color = JColorChooser.showDialog(FrameExample2.this,
                 "Choosing a color", color);
          if (color == null )
            color = Color.pink;
          container.setBackground(color);
          container.repaint();
        }
      }
    );
    container.add(myButton, BorderLayout.SOUTH);
  //  setBackground(Color.yellow);
  }

  public void actionPerformed(ActionEvent e )
  {

  }

  public static void main(String args[])
  {
    FrameExample2 app = new FrameExample2();
  //  app.setSize(200,300);
    app.addWindowListener(
     new WindowAdapter() {
          public void windowClosing( WindowEvent e )
          {
            System.exit(0);
          }
        }
      );
    app.setSize(400, 200);
    app.setVisible(true);
  }
}
